import os
import time

from config.app_config import AppConfig
from config.execute_operation_config import operations_config
from src.custom_logger import CustomLogger
from src.leetcode_scraper import LeetCodeScraper
from src.requests_manager import RequestsManager
from src.selenium_manager import SeleniumManager


# main.py
def main():

    logger.info('manul loin by selenium')
    selenium_manager = SeleniumManager()
    selenium_manager.manual_login()
    logger.info('init requests manager by requests')
    requests_manager = RequestsManager(selenium_manager)
    logger.info('init leetcodescraper')
    LeetCodeScraper(requests_manager)
    leetcode_scraper = LeetCodeScraper(requests_manager)
    logger.info('run the scraper with operations config')
    leetcode_scraper.run(operations_config)
    logger.info('colse selenium')
    selenium_manager.close()

if __name__ == "__main__":
    logger = CustomLogger()
    logger.set_log_file(log_file="leetcode_automation.log")
    while True:
        try:
            main()
        except Exception as e:
            logger.error(f"main error: {e}")

        time.sleep(600)